<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>发票管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<script type="text/javascript">
    var dtlId = '${dtlId}';
    var paySchNo = '${paySchNo}';
    var grid = null;
    $(function () {
        if (StringUtils.isNotEmpty(dtlId) && StringUtils.isNotEmpty(paySchNo)) {
            $("#searchConditonId").hide();
            $("#searchBtn").hide();
            $("#clearBtn").hide();
        }
        //grid
        initGrid();
        $("#searchBar").ligerForm();
        $("#searchBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            ;
            grid.reload();
        });
    });

    function clearBtn() {
        $("#searchBar").ligerForm();
        var form = new liger.get("searchBar");
        form.setData({
            lsCntNo: " ",
            cstNm: " ",
            prjTypCd: " ",
            isHaveVeh: " ",
            isUploadFile: " ",
            paySchNo: " ",
            certNo: " ",
            buOrgCd: " ",
            invoicenum: ""
        });
    }

    //初始化列表
    function initGrid() {
        var params = {};
        if (StringUtils.isNotEmpty(dtlId)) {
            params["dtlId"] = dtlId;
        }
        if (StringUtils.isNotEmpty(paySchNo)) {
            params["paySchNo"] = paySchNo;
        }
        $("#grid").ligerGrid({
            url: '<%=path%>/project/prjPrdInvoice/initList.do',
            method: 'get',
            parms: params,
            columns: [
                {
                    display: '发票号码', name: 'invoicenum', minWidth: 80, align: 'left',
                    render: function (rowdata, rowindex, value, column) {
                        var no = rowdata.invoicenum == null ? " " : rowdata.invoicenum;
                        var h = '';
                        if (no) {
                            h = '<a  href="javascript:detailBtn(';
                            h += "'" + rowdata.id + "',";
                            h += "'" + rowdata.cstNm + "',";
                            h += "'" + rowdata.lsCntNo + "',";
                            h += "'" + rowdata.prdNm + "',";
                            h += "'" + rowdata.dtlId + "'";
                            h += ')">' + no + '</a>'
                        }
                        return h;
                    },
                    enabledSort: true
                },
                {display: '合同号', name: 'lsCntNo', minWidth: 80, align: 'left', enabledSort: true},
                {display: '客户名称', name: 'cstNm', minWidth: 60, align: 'left', enabledSort: true},
                {display: '项目类型', name: 'prjTypCdNm', minWidth: 60, align: 'left', enabledSort: true},
                {display: '业务类型', name: 'bizTypCdNm', minWidth: 60, align: 'left', enabledSort: true},
                {display: '租赁物名称', name: 'prdNm', minWidth: 80, align: 'left', enabledSort: true},
                {display: '支付表号', name: 'paySchNo', minWidth: 100, align: 'left', enabledSort: true},
                /*    { display: '型号', name: 'prdMdl', minWidth: 100,enabledSort:true}, 	 */
                {
                    display: '发票是否上传', name: 'fileId', minWidth: 80, align: 'left', enabledSort: true,
                    render: function (rowdata, rowindex, value) {
                        var h = '';
                        if (StringUtils.isEmpty(rowdata.fileId)) {
                            h = '未上传';
                        } else {
                            h = '已上传';
                        }
                        return h;
                    }
                },
                {
                    display: '发票审核状态', name: 'audStsCdNm', minWidth: 80, align: 'left', enabledSort: true
                },
                {
                    display: '发票类型', name: 'flagNm', minWidth: 80, align: 'left', enabledSort: true,
                },
                {
                    display: '操作',
                    isSort: false,
                    width: 200,
                    align: 'left',
                    render: function (rowdata, rowindex, value) {
                        var h = "";//audStsCd，PRJ0112）：0-未审核， 1-审核中，2-审核通过
                        if (rowdata.invoicenum) {
                            h += '<a  class="sq-button-hasicon" href="javascript:detailBtn(';
                            h += "'" + rowdata.id + "',";
                            h += "'" + rowdata.cstNm + "',";
                            h += "'" + rowdata.lsCntNo + "',";
                            h += "'" + rowdata.prdNm + "',";
                            h += "'" + rowdata.dtlId + "'";
                            h += ')"><i class="sqBtnIco_4"></i>查看</a>'
                        }
                        if (rowdata.invoicenum && (rowdata.audStsCd == 0 || rowdata.audStsCd == 1 || rowdata.audStsCd == 3 || rowdata.audStsCd == 4)) {
                            h += '<a class="sq-button-hasicon" href="javascript:modifyBtn(';
                            h += "'" + rowdata.id + "',";
                            h += "'" + rowdata.dtlId + "',";
                            h += "'" + rowdata.flag + "',";
                            h += "'" + rowdata.audStsCd + "',";
                            h += "'" + rowdata.cstNm + "',";
                            h += "'" + rowdata.lsCntNo + "',";
                            h += "'" + rowdata.paySchNo + "',";
                            h += "'" + rowdata.paySchId + "',";
                            h += "'" + rowdata.prjId + "',";
                            h += "'" + rowdata.prdNm + "'";
                            h += ')"><i class="sqBtnIco_4"></i>修改</a>';

                            h += '<a class="sq-button-hasicon" href="javascript:removeBtn(';
                            h += "'" + rowdata.id + "'";
                            h += ')"><i class="sqBtnIco_7"></i>删除</a>';
                        }
                        return h;
                    }
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            isSingleCheck: true,
            allowUnSelectRow: true,
            alternatingRow: true,
            rownumbers: true,
            enabledEdit: true,
        });
        grid = liger.get("grid");
        grid.setHeight(500);

    }

    //格式化为人民币格式
    function renderAmt(rowdata, rowindex, value) {
        var h = "￥" + FormatMoney(value)
        return h;
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value && value != '') {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }


    //添加发票信息
    function addBtn() {
        var callback = function () {
            grid.reload();
        }
        var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
            return;
        }
        var dtlId = selectedRows[0].dtlId;
        var prjId = selectedRows[0].prjId;
        var paySchId = selectedRows[0].paySchId;
        var paySchNo = selectedRows[0].paySchNo;
        var cstNm = selectedRows[0].cstNm;
        var prdNm = selectedRows[0].prdNm;
        var lsCntNo = selectedRows[0].lsCntNo;
        var flag = selectedRows[0].flag;
        var detailFlag = false;
        var timestamp = new Date().getTime();
        $.ajax({
            type: 'GET',
            dataType: 'json',
            data: {lsCntNo:lsCntNo,paySchNo:paySchNo},
            url: '<%=path%>/project/prjPrdInvoice/getPrjPrdInvoiceList.do',
            success: function (msg) {
                if (msg.data > 6) {
                    $.ligerDialog.SQalert({content: "发票资料已超上限", SQ_type: "warring"});
                    return;
                }
                var url = '<%=path%>/project/prjPrdInvoice/toAddPage.do?detailFlag=' + detailFlag + '&&dtlId=' + dtlId + '&&prjId=' + prjId + '&&paySchId=' + paySchId + '&&paySchNo=' + paySchNo + '&&cstNm=' + cstNm + '&&prdNm=' + prdNm + '&lsCntNo=' + lsCntNo + '&flag=' + flag
                //console.log(url);
                Add_navTab('tab_prj_prd_invoince_info_add' + timestamp, '添加发票信息', url, function () {
                    grid.reload();
                });
            }
        });
    }

    //修改发票信息
    function modifyBtn(id, dtlId, flag, audStsCd, cstNm, lsCntNo, paySchNo, paySchId, prjId, prdNm) {


        var url = '<%=path%>/project/prjPrdInvoice/toAddPage.do?id=' + id + '&&dtlId=' + dtlId + '&&prjId=' + prjId + '&&paySchId=' + paySchId + '&&paySchNo=' + paySchNo + '&&cstNm=' + cstNm + '&&prdNm=' + prdNm + '&lsCntNo=' + lsCntNo + '&flag=' + flag
        Add_navTab('tab_prj_prd_invoice_modify' + id, '修改发票信息', url, function () {
            grid.reload();
        });

    }

    //查看发票信息
    function detailBtn(id, cstNm, lsCntNo, prdNm, dtlId) {
        var detailFlag = true;
        Add_navTab('tab_prj_prd_invoice_detail' + id, '查看发票详情', '<%=path%>/project/prjPrdInvoice/toDetailPage.do?detailFlag=' + detailFlag + '&&id=' + id + '&&dtlId=' + dtlId + '&&cstNm=' + cstNm + '&&prdNm=' + prdNm + '&lsCntNo=' + lsCntNo);
    }

    function iframeResize() {
        if (parent.mainApp) {
            parent.mainApp.parentTab.onResize();
        }
        ;
    }

    //删除所选发票信息
    function removeBtn(id) {
        $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
            if (flag == false) return;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {"id":id},
                url: '<%=path%>/project/prjPrdInvoice/removeById.do',
                success: function (msg) {
                    if (msg.success == 1) {
                        grid.reload();
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }
</script>

<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <div class="searchArea">
            <form id="searchBar">
                <div class="fieldset1 clearFix" id="searchConditonId">
                    <div class="fieldBox col_33" id="searchCstNmId">
                        <div class="label">客户名称</div>
                        <div class="field">
                            <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                        </div>
                    </div>
                    <div class="fieldBox col_33" id="searchCstNmId">
                        <div class="label">合同号</div>
                        <div class="field">
                            <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                        </div>
                    </div>
                    <div class="fieldBox col_33" id="searchCstNmId">
                        <div class="label">支付表号</div>
                        <div class="field">
                            <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                        </div>
                    </div>
                    <div class="fieldBox col_33" id="searchCstNmId">
                        <div class="label">发票号码</div>
                        <div class="field">
                            <input name="invoicenum" id="invoicenum" type="text" class="ui-textbox" value="">
                        </div>
                    </div>
                    <div class="fieldBox col_33" id="searchPrjTypCdId">
                        <div class="label">项目类型</div>
                        <div class="field">
                            <select name="prjTypCd" id="prjTypCd">
                                <option value="  " selected="selected">--请选择--</option>
                                <c:forEach items="${projectTypeList}" var="opt">
                                    <option value="${opt.key}">${opt.value}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <div class="fieldBox col_33" id="searchBizTypCdId">
                        <div class="label">发票是否上传</div>
                        <div class="field">
                            <select name="isUploadFile" id="isUploadFile">
                                <option value="  " selected="selected">--请选择--</option>
                                <option value="1">是</option>
                                <option value="2">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="fieldBox col_33" id="searchBuOrgCdId">
                        <div class="label">所属事业部</div>
                        <div class="field">
                            <select name="buOrgCd" id="buOrgCd">
                                <option value=" " seleted>请选择</option>
                                <c:forEach items="${buOrgCdList }" var="org">
                                    <c:if test="${currentBuOrgCd == org.key }">
                                        <option value="${org.key }" selected>${org.value }</option>
                                    </c:if>
                                    <c:if test="${currentBuOrgCd != org.key }">
                                        <option value="${org.key }">${org.value }</option>
                                    </c:if>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <div class="fieldBox col_33" id="searchInvoiceAudStsCdNm">
                        <div class="label">发票审核状态</div>
                        <div class="field">
                            <select name="AudStsCd" id="AudStsCd">
                                <option value="  " selected="selected">--请选择--</option>
                                <c:forEach items="${invoiceAudStsList}" var="opt">
                                    <option value="${opt.key}">${opt.value}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <div class="clearFix"></div>
                </div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
                    <span id="addBtn" onclick="addBtn();" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_5"></i> -->新增</span>
                    <!-- <span id="lookBtn" onclick="lookBtn('190417999000004','');" class="sq-button sq-button-round">查看</span> -->
                </div>
            </form>
        </div>
        <div id="grid" class="sq-grid"></div>

    </div>
</div>
</div>
</body>
</html>